<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="./assets/mui/css/mui.min.css">
    <link rel="stylesheet" href="css/base.css">
    <link rel="stylesheet" href="assets/fontAwesome/css/font-awesome.min.css">
    <script src="./assets/mui/js/mui.min.js"></script>
    <title>Document</title>
    <style>
        .getCode{
            position: absolute;
            top: 50%;
            right: 10px;
            transform: translateY(-50%)
        }
        .mui-content,
        .mui-content input{
            font-size: 14px;
        }
    </style>
</head>
<body>
    <!-- 头部 -->
	<header class="mui-bar mui-bar-nav my-header">
		<h1 class="mui-title">乐淘云购</h1>
		<a class="mui-icon mui-icon-search mui-pull-right"></a>
    </header>
    <!-- 底部 -->
	<nav class="mui-bar mui-bar-tab my-footer">
		<a class="mui-tab-item mui-active" href="index.html">
			<span class="mui-icon mui-icon-home"></span>
			<span class="mui-tab-label">首页</span>
		</a>
		<a class="mui-tab-item" href="category.html">
			<span class="mui-icon mui-icon-bars"></span>
			<span class="mui-tab-label">分类</span>
		</a>
		<a class="mui-tab-item" href="cart.html">
			<span class="mui-icon fa fa-shopping-cart"></span>
			<span class="mui-tab-label">购物车</span>
		</a>
		<a class="mui-tab-item" href="user.html">
			<span class="mui-icon mui-icon-person"></span>
			<span class="mui-tab-label">会员中心</span>
		</a>
    </nav>
    
	<div class="mui-content">
        <form class="mui-input-group">
            <div class="mui-input-row">
                <label>旧密码</label>
            <input name="oldPwd" id="oldPwd" type="password" class="mui-input-password" placeholder="请输入旧密码">
            </div>
            
            <div class="mui-input-row">
                <label>新密码</label>
                <input name="newPwd" id="newPwd" type="password" class="mui-input-password" placeholder="请输入新密码">
            </div>
            <div class="mui-input-row">
                <label>确认新密码</label>
                <input name="repassword" id="repassword" type="password" class="mui-input-password" placeholder="请输入密码">
            </div>
            <div class="mui-input-row">
                <label>认证码</label>
                <input id="code" type="text" class="mui-input-clear" placeholder="认证码" name="code">
                <a href="javascript:;" class="getCode" id="getCode">获取认证码</a>
            </div>
            <div class="mui-button-row">
                <button type="button" class="mui-btn mui-btn-primary" id="modify-btn">确认修改密码</button>
            </div>
        </form>
        
	</div>
</body>
<script src="assets/zepto/zepto.min.js"></script>
<script src="js/public.js"></script>
<script>
    $(function(){
        //获取验证码
        $(".getCode").on("click",function(){
            $.ajax({
                type:"get",
                url:"/user/vCodeForUpdatePassword",
                success:function(res){
                    console.log(res);
                }
            });
        });
        //修改密码
        $("#modify-btn").on("click",function(){
            //获取用户输入信息
            var oldPwd = $("#oldPwd").val();
            var newPwd =$("#newPwd").val();
            var repassword = $("#repassword").val();
            var code = $("#code").val();
            //判断用户信息
            if(oldPwd.trim() == ""){
                mui.toast("旧密码不能为空");
                return;
            }
            if(newPwd.trim() == ""){
                mui.toast("旧密码不能为空");
                return;
            }
            if(repassword.trim() == ""){
                mui.toast("旧密码不能为空");
                return;
            }else if(newPwd != repassword){
                mui.toast("确认密码要和新密码一致");
                return;
            }
            if(code.trim() == ""){
                mui.toast("验证码不能为空");
                return;
            }
            //获取更新密码
            $.ajax({
                type:"post",
                url:"/user/updatePassword",
                data:{
                    "oldPassword":oldPwd,
                    "newPassword":newPwd,
                    "vCode":code
                },
                dataType:"json",
                success:function(res){
                    // console.log(res);
                    if(res.success){
                        mui.toast("修改密码成功");
                        setTimeout(() => {
                            location.href = "login.html";
                        }, 1000);
                        
                    }
                }

            });
            
        });

    });
</script>
</html>